package com.ruoyi.server.api.subscribe.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.exception.errorCode.CommonException;
import com.ruoyi.server.api.subscribe.model.CourseSubscribeModel;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.server.api.subscribe.domain.CourseSubscribe;
import com.ruoyi.server.api.subscribe.service.ICourseSubscribeService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;
import org.springframework.web.multipart.MultipartFile;

/**
 * 团课信息Controller
 *
 * @author hjh
 * @date 2024-06-10
 */
@RestController
@RequestMapping("/subscribe/courseSubscribe/")
public class CourseSubscribeController extends BaseController {
    @Autowired
    private ICourseSubscribeService courseSubscribeService;

    /**
     * @param courseSubscribe
     * @Author hjh
     * @Description 查询团课信息
     * @Date 2024/6/11 10:25
     * @Return com.ruoyi.common.core.page.TableDataInfo
     */
    @PreAuthorize("@ss.hasPermi('subscribe:courseSubscribe:list')")
    @GetMapping("/list")
    public TableDataInfo list(CourseSubscribe courseSubscribe) {
        startPage();
        List<CourseSubscribe> list = courseSubscribeService.selectCourseSubscribeList(courseSubscribe);
        return getDataTable(list);
    }

    /**
     * 导出团课信息列表
     */
    @PreAuthorize("@ss.hasPermi('subscribe:courseSubscribe:export')")
    @Log(title = "团课信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CourseSubscribe courseSubscribe) {
        List<CourseSubscribe> list = courseSubscribeService.selectCourseSubscribeList(courseSubscribe);
        ExcelUtil<CourseSubscribe> util = new ExcelUtil<CourseSubscribe>(CourseSubscribe.class);
        util.exportExcel(response, list, "团课信息数据");
    }

    /**
     * 获取团课信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('subscribe:courseSubscribe:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(courseSubscribeService.selectCourseSubscribeById(id));
    }

    /**
     * 新增团课信息
     */
    @PreAuthorize("@ss.hasPermi('subscribe:courseSubscribe:add')")
    @Log(title = "团课信息", businessType = BusinessType.INSERT)
    @PostMapping("add")
    public AjaxResult add(CourseSubscribeModel courseSubscribeModel) throws Exception {
        return courseSubscribeService.insertCourseSubscribe(courseSubscribeModel);
    }

    /**
     * 修改团课信息
     */
    @PreAuthorize("@ss.hasPermi('subscribe:courseSubscribe:edit')")
    @Log(title = "团课信息", businessType = BusinessType.UPDATE)
    @PutMapping("updateCourse")
    public AjaxResult edit(CourseSubscribeModel courseSubscribeModel) throws Exception {
        AjaxResult ajaxResult = courseSubscribeService.updateCourseSubscribe(courseSubscribeModel);
        return ajaxResult;
    }

    /**
     * 删除团课信息
     */
    @PreAuthorize("@ss.hasPermi('subscribe:courseSubscribe:remove')")
    @Log(title = "团课信息", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(courseSubscribeService.deleteCourseSubscribeByIds(ids));
    }


    /**
     * @param id
     * @Author hjh
     * @Description 修改团课信状态
     * @Date 2024/6/11 15:06
     * @Return com.ruoyi.common.core.domain.AjaxResult
     */
    @Log(title = "团课信息", businessType = BusinessType.UPDATE)
    @PutMapping("updateCourseState")
    public AjaxResult updateCourseState(Integer id) {
        AjaxResult result = courseSubscribeService.updateCourseState(id);
        return AjaxResult.success(result);
    }

    /**
     * @param courseSubscribe
     * @Author hjh
     * @Description 查询团课信息（已发布）
     * @Date 2024/6/12 8:47
     * @Return com.ruoyi.common.core.page.TableDataInfo
     */
    @GetMapping("/getReleaseCourse")
    public TableDataInfo getReleaseCourse(CourseSubscribe courseSubscribe) {
        startPage();
        List<CourseSubscribe> list = courseSubscribeService.getReleaseCourse(courseSubscribe);
        return getDataTable(list);
    }

    /**
     * @param courseSubscribe
     * @Author hjh
     * @Description 查询团课信息（过往团课）
     * @Date 2024/6/12 8:47
     * @Return com.ruoyi.common.core.page.TableDataInfo
     */
    @GetMapping("/getAbnormalCourse")
    public TableDataInfo getAbnormalCourse(CourseSubscribe courseSubscribe) {
        startPage();
        List<CourseSubscribe> list = courseSubscribeService.getAbnormalCourse(courseSubscribe);
        return getDataTable(list);
    }

    /**
     * @param id
     * @param cancelCause
     * @Author hjh
     * @Description 撤销团课(状态 - - > 作废)
     * @Date 2024/6/12 15:16
     * @Return com.ruoyi.common.core.domain.AjaxResult
     */
    @PutMapping("updateCancelRelease")
    public AjaxResult updateCancelRelease(Integer id, String cancelCause) {
        AjaxResult ajaxResult = courseSubscribeService.updateCancelRelease(id, cancelCause);
        return AjaxResult.success(ajaxResult);
    }

    /**
     * @Author hjh
     * @Description 获取当前用户所在场馆标识
     * @Date 2024/6/13 14:39
     * @Return com.ruoyi.common.core.domain.AjaxResult
     */
    @GetMapping("getVenueUniqueIdentifier")
    public AjaxResult getVenueUniqueIdentifier() {
        return courseSubscribeService.getVenueUniqueIdentifier();
    }
    
    /**
    * @Author hjh
    * @Description 获取教练信息
    * @Date 2024/6/14 10:40
    * @Return com.ruoyi.common.core.domain.AjaxResult
    
    */
    @GetMapping("getCouchInfo")
    @Log(title = "获取教练信息", businessType = BusinessType.OTHER)
    public AjaxResult getCouchInfo(){
        return courseSubscribeService.getCouchInfo();
    }
}
